{layout name="common/layout" /}
<link rel="stylesheet" type="text/css" href="__MERCHANT_STATIC__/style/css/message/message.css?v=2017.10.25" />
<div class="Hui-article-box" style="margin-top: 37px;">
		<div class="newCrumbs " style="display: inline-table;width: 80%;position: relative;">消息中心
			<span class="c-gray en">&gt;</span>订单消息
		</div>
                <div class="borrowOrder_form">
                        <form action="" method="get" style="border:0;margin: 0 auto;">
                                <?php $keyword = input('param.keyword'); ?>
                                <span >关键字</span><input type="text" value="{$keyword}" class="input-text" style="width:250px" placeholder="输入关键字" id="" name="keyword">
                                <button type="submit" class="btn btn-success radius" id="btn_sub" name=""> 搜索</button>
                        </form>
                </div>
		<div style="display: inline-table;position: relative;float: right;top:5px;">
			<a><span class="index_orderType readall" style="width: 100px;">全部标为已读</span></a>
		</div>
	<div class="Hui-article">
		<ul class="message_main_list">
			{foreach ($orderInfo as $k =>$v)}
				<li class="message_main_single {if $v['is_read'] eq '1'}message_main_single--read{else}message_main_single--unread{/if}" data-id="{$v['id']}" >
					<p class="message_main_text">
						{$v['title']}
						<br>
						<br>
						<a  data-order="{if condition="$v['order_id'] gt '0'"}{$v['order_id']}{else/}b-{$v['book_order_id']}{/if}" href="javascript:void(0);">{$v['content']}</a>
					</p>
					<span class="message_main_time">
						<span>
							<?php echo date('Y-m-d H:i:s', $v['create_time']); ?>
						</span>	
						<span>
							<?php echo date('Y-m-d H:i:s', $v['create_time']); ?>
						</span>	
					</span>
				</li>
			{/foreach}
		</ul>	
		<div class="cl">
			{$orderInfo->render()}
		</div>
</div>
<script>
	/* 点击事件 */
	$(".message_main_list").on("click",'.message_main_single a',function(event){
		event.stopPropagation();
		var order = $(this).attr("data-order");
		if(order.substring(0,1) == 'b'){
            order = order.substring(2,order.length);
            window.location.href="/merchant/book/borrowDetail.html?order_id="+order;
		}else{
            window.location.href="/merchant/order/details.html?id="+$(this).attr("data-order");
		}
	});

	$(".readall").click(function () {
		$.post("{:url('message/readAll')}",{},function (data) {
		    if(data.status == 1){
		        alert("标记成功");
		        window.location.reload();
			}else{
                alert("标记失败");
			}
        },'json');
    });
	
	$(".message_main_list").on("click",'.message_main_single',function(){
		var self=this;
		var id=$(this).data("id");
		/* 判断当前消息是否已读，已读消息不再发送请求 */
		if($(this).hasClass("message_main_single--show")){
			$(this).removeClass("message_main_single--show");
		}else{
			$(this).addClass("message_main_single--show");	
			$(this).siblings().removeClass("message_main_single--show");
		}
		if($(this).hasClass("message_main_single--read")){
			return false;
		}else{
			/* $(this).find("a").click(function(event){ */
			/* 	event.stopPropagation(); */
				$.ajax({
				url: "../../api/message/readOrderMessage",
				type: "POST",
				data: {
					msg_id:id
				},
				async: true,
				dataType: "json",
				success: function (response) {
                    if (response.status == 1) {
                        $(self).removeClass("message_main_single--unread").addClass("message_main_single--read");
                        if($('#message_count').text() > 1) {
                            $('#message_count').text($('#message_count').text() - 1);
						}else{
                            $('#message_count').hide();
						}
                    }
				},
				error: function (error) {
	
				}
			});
		/* 	}) */
			
		}
	})
	
</script>